package org.demo.datasoureces.config;

import lombok.Data;
import org.springframework.context.annotation.Configuration;

import lombok.Data;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

//@Configuration
@Data
public class DataSoureceConfig {

    @Bean(name = "dataSource")
    public DataSource getDataSource(){
        DataSource dataSource = null;
        File f = new File("./src/main/resources/dataSourceConf.yml");
        try {
            dataSource = YamlShardingSphereDataSourceFactory.createDataSource(f);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("datasrouce:" + dataSource);
        return dataSource;
    }
}
